package com.dsr.controller;

import com.dsr.consts.Result;
import com.dsr.entity.Flower;
import com.dsr.service.SearchService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author dsr
 * @since 2020-10-10
 */
@Api( tags = {"search表控制层"})
@RestController
@RequestMapping("/search")
public class SearchController {
    @Autowired
    private SearchService searchService;

    @ApiOperation(value = "keyword", notes = "关键字搜索", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Map", name = "keyword", value = "keyMap")
    })
    @PostMapping
    public Result search(@RequestBody Map<String,String> keyMap){
        return searchService.search(keyMap);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", required = true,dataType = "string", name = "id", value = "id")
    })
    @ApiOperation(value = "栏目搜索", notes = "栏目搜索", httpMethod = "GET")
    @GetMapping("/{id}")
    public Result getFlowerBySection(@PathVariable String id){
        return searchService.getFlowerBySection(id);
    }

    @ApiOperation("查询接口")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "页", required = true),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页大小", required = true),
    })
    @ApiParam(name = "flower", value = "查询字段", required = true)
    @PostMapping("/list/{page}/{size}")
    public Result query(@PathVariable int page, @PathVariable int size, @RequestBody Flower flower) {
        return searchService.query(page, size, flower);
    }
}
